/**
 * Copyright 2013 Net355 Co,.Ltd. 
 * All rights reserved.
 *
 * "ThreadHelper.java is for what: "
 * 
 * Create by Ray at 2014-1-10 上午9:21:45.
 * Ray [email:rayinhangzhou@126.com]
 * 
 * Revision History
 *
 * Date            Programmer                   Notes
 * ---------    ---------------------  -----------------------------------
 * 2014-1-10            Ray                       initial
 **/


package com.net355.eblog.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.net355.eblog.models.EbNote;
import com.net355.eblog.models.EbTag;


public class ThreadHelper {
	private static Log LOG = LogFactory.getLog(ThreadHelper.class);
	private static Object locker_note = new Object();
	private static Object locker_tag = new Object();

	/**
	 * 新增笔记访问数量
	 * @param guid
	 * @return
	 */
	public static Runnable incrementNoteView(final String guid){
		return new Runnable() {
			@Override
			public void run() {
				try {
					synchronized (locker_note) {
						EbNote note = (EbNote) CacheHelper.get_cache(guid);
						note.setViewCount(note.getViewCount()+1);
						CacheHelper.set_cache(guid, note);
					}
				} catch (Exception e) {
					LOG.error("incrementNoteView error--->>>", e);
				}
			}
		};
	}

	public static Runnable incrementTagClick(final String guid){
		return new Runnable() {
			@Override
			public void run() {
				try {
					synchronized (locker_tag) {
						EbTag tag = (EbTag) CacheHelper.get_cache(guid);
						tag.setClickCount(tag.getClickCount()+1);
						CacheHelper.set_cache(guid, tag);
					}
				} catch (Exception e) {
					LOG.error("incrementTagClick error--->>>", e);
				}
			}
		};
	}

}
